package com.sjgtw.cloud.web.equipmentCheck.service.impl;

import com.sjgtw.cloud.common.core.constant.CacheConstants;
import com.sjgtw.cloud.common.core.utils.DateUtils;
import com.sjgtw.cloud.common.core.utils.SecurityUtils;
import com.sjgtw.cloud.common.redis.service.RedisService;
import com.sjgtw.cloud.system.api.model.LoginUser;
import com.sjgtw.cloud.web.equipmentCheck.domain.EquipmentCheck;
import com.sjgtw.cloud.web.equipmentCheck.mapper.EquipmentCheckMapper;
import com.sjgtw.cloud.web.equipmentCheck.service.IEquipmentCheckService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 防洪设备检查Service业务层处理
 * 
 * @author lvyoufang
 * @date 2024-03-14
 */
@Service
public class EquipmentCheckServiceImpl implements IEquipmentCheckService 
{
    @Autowired
    private EquipmentCheckMapper equipmentCheckMapper;

    @Autowired
    private RedisService redisService;

    /**
     * 查询防洪设备检查
     * 
     * @param id 防洪设备检查主键
     * @return 防洪设备检查
     */
    @Override
    public EquipmentCheck selectEquipmentCheckById(Long id)
    {
        return equipmentCheckMapper.selectEquipmentCheckById(id);
    }

    /**
     * 查询防洪设备检查列表
     * 
     * @param equipmentCheck 防洪设备检查
     * @return 防洪设备检查
     */
    @Override
    public List<EquipmentCheck> selectEquipmentCheckList(EquipmentCheck equipmentCheck)
    {
        return equipmentCheckMapper.selectEquipmentCheckList(equipmentCheck);
    }

    /**
     * 新增防洪设备检查
     * 
     * @param equipmentCheck 防洪设备检查
     * @return 结果
     */
    @Override
    public int insertEquipmentCheck(EquipmentCheck equipmentCheck)
    {
        String token = SecurityUtils.getToken();
        String userKey = CacheConstants.LOGIN_TOKEN_KEY + token;
        LoginUser user = redisService.getCacheObject(userKey);

        equipmentCheck.setCreateUserId(user.getUserid());
        equipmentCheck.setCreateBy(user.getUsername());
        equipmentCheck.setCreateTime(DateUtils.getNowDate());
        return equipmentCheckMapper.insertEquipmentCheck(equipmentCheck);
    }

    /**
     * 修改防洪设备检查
     * 
     * @param equipmentCheck 防洪设备检查
     * @return 结果
     */
    @Override
    public int updateEquipmentCheck(EquipmentCheck equipmentCheck)
    {
        String token = SecurityUtils.getToken();
        String userKey = CacheConstants.LOGIN_TOKEN_KEY + token;
        LoginUser user = redisService.getCacheObject(userKey);

        equipmentCheck.setUpdateBy(user.getUsername());
        equipmentCheck.setUpdateTime(DateUtils.getNowDate());
        return equipmentCheckMapper.updateEquipmentCheck(equipmentCheck);
    }

    /**
     * 批量删除防洪设备检查
     * 
     * @param ids 需要删除的防洪设备检查主键
     * @return 结果
     */
    @Override
    public int deleteEquipmentCheckByIds(String[] ids)
    {
        return equipmentCheckMapper.deleteEquipmentCheckByIds(ids);
    }

    /**
     * 删除防洪设备检查信息
     * 
     * @param id 防洪设备检查主键
     * @return 结果
     */
    @Override
    public int deleteEquipmentCheckById(Long id)
    {
        return equipmentCheckMapper.deleteEquipmentCheckById(id);
    }
}
